﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MathTest {
    class Test5 {

        public static void getMatrixResult() {

            Console.WriteLine("输入矩阵的行数：");
            int rowNumber = int.Parse(Console.ReadLine());
            Console.WriteLine("输入矩阵的列数：");
            int lineNumber = int.Parse(Console.ReadLine());

            double[,] matrixArry = new double[20, 20];

            //定义每列总和的存储数组：
            double[] sum = new double[20];

            for (int i = 0; i < rowNumber; i++) {
                for (int j = 0; j < lineNumber; j++) {
                    Console.WriteLine("请输入第" + (i + 1) + "行第" + (j + 1) + "个数的值：");
                    matrixArry[i, j] = int.Parse(Console.ReadLine());
                }
            }
            Console.WriteLine("矩阵如下：");
            for (int i = 0; i < rowNumber; i++) {
                for (int j = 0; j < lineNumber; j++) {
                    Console.Write(matrixArry[i, j] + "\t");
                }
                Console.WriteLine();
            }

            for (int j = 0; j < lineNumber; j++) {
                for (int i = 0; i < rowNumber; i++) {
                    sum[j] += matrixArry[i, j];
                }
                Console.WriteLine("第" + (j + 1) + "列的平均值为" + sum[j] / rowNumber);

            }

        }
        public static void getMathEquation() {
            double[] answer = new double[5];

            Console.WriteLine("求方程a*x~2 + b*x + c = 0的实根和复根");
            Console.WriteLine("输入a的值：");
            double a = double.Parse(Console.ReadLine());

            Console.WriteLine("输入b的值：");
            double b = double.Parse(Console.ReadLine());

            Console.WriteLine("输入c的值：");
            double c = double.Parse(Console.ReadLine());

            double d = (b * b) - (4 * a * c);
            if (a == 0) {
                Console.WriteLine("a不能为0,请重新输入：");
                return;
            }

            if (d > 0) {
                answer[0] = ((-b) + Math.Sqrt(d)) / (2 * a);
                answer[1] = ((-b) - Math.Sqrt(d)) / (2 * a);
                Console.WriteLine("该方程在实数范围有两个不同的实数解，分别为：x1="+answer[0]+",x2="+answer[1]);
            } else if (d == 0) {
                answer[0] = answer[1] = ((-b) + Math.Sqrt(d)) / (2 * a);
                Console.WriteLine("该方程在实数范围有两个相同的实数解，x1=x2=" + answer[0]);
            } else {
                Console.WriteLine("该方程在实数范围内无解");
            }

        }

        public static void getMaxAndMin() {
            double[] graderNumber = new double[20];

            for (int i = 0; i < 10; i++) {
                Console.WriteLine("请输入第" + (i + 1) + "个同学的成绩：");
                graderNumber[i] = double.Parse(Console.ReadLine());
            }

            for (int i = 0; i < 10; i++) {
                for (int j = 9; j > i; j--) {
                    if (graderNumber[i] > graderNumber[j]) {
                        double temp = graderNumber[i];
                        graderNumber[i] = graderNumber[j];
                        graderNumber[j] = temp;
                    }
                }
            }

            double sum = 0;
            for (int i = 0; i < 10; i++) {
                sum += graderNumber[i];
            }
            Console.WriteLine("学生成绩的平均成绩为：" + (sum / 10));
            Console.WriteLine("最高分为：" + graderNumber[9]);
            Console.WriteLine("最低分为：" + graderNumber[0]);
        }

        public static void MaoPao() {
            double[] arryNumber = new double[10];
            for (int i = 0; i < 10; i++) {
                Console.WriteLine("请输入第" + (i + 1) + "个实数");
                arryNumber[i] = double.Parse(Console.ReadLine());
            }
            Console.WriteLine("排序前的数组为：");
            for (int i = 0; i < 10; i++) {
                Console.Write(arryNumber[i] + "、");
            }
            Console.WriteLine();
            //排序
            for (int i = 0; i < 10; i++) {
                for (int j = 9; j > i; j--) {
                    if (arryNumber[i] > arryNumber[j]) {
                        double temp = arryNumber[i];
                        arryNumber[i] = arryNumber[j];
                        arryNumber[j] = temp;
                    }
                }
            }
            Console.WriteLine("排序后的数组为：");
            for (int i = 0; i < 10; i++) {
                Console.Write(arryNumber[i] + "、");
            }

        }
    }
}
